package com.yuandian.customer.perception.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.customer_perception.po.*;
import com.yuandian.api.customer_perception.vo.*;
import com.yuandian.api.management.entity.ConfAlarmIndicators;
import com.yuandian.api.management.entity.ConfBusiness;
import com.yuandian.api.management.entity.ConfSystem;
import com.yuandian.api.management.feign.RemoteAlarmIndicatorsService;
import com.yuandian.api.management.feign.RemoteBusinessService;
import com.yuandian.api.management.feign.RemoteSystemService;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.constant.ConfigKey;
import com.yuandian.customer.perception.mapper.BusinessAlarmMapper;
import com.yuandian.customer.perception.service.IBusinessAlarmService;
import com.yuandian.customer.perception.util.RemoteQueryUtil;
import com.yuandian.enums.TableNameEnum;
import com.yuandian.po.MergeDataConfig;
import com.yuandian.po.MergeField;
import com.yuandian.po.MultipleTableInfo;
import com.yuandian.utils.DynamicTableNameUtil;
import com.yuandian.utils.MergeDataUtil;
import com.yuandian.utils.PageDataInfo;
import com.yuandian.utils.StringUtils;
import com.yuandian.utils.poi.ExcelTitleUtils;
import com.yuandian.utils.poi.ExcelUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * 说明：业务告警service实现
 * @Author yanjun
 * @Date 2021/3/30 9:23
 */
@Slf4j
@Service
public class BusinessAlarmServiceImpl implements IBusinessAlarmService {

	private static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
	private static final DateTimeFormatter dropSec = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:00");

	@Autowired
	private BusinessAlarmMapper businessAlarmMapper;

	@Autowired
	private RemoteQueryUtil remoteQueryUtil;

	private String QUARY_NOT_NULL_FLAG;

	@PostConstruct
	public void init() {
		try {
			QUARY_NOT_NULL_FLAG = remoteQueryUtil.queryBasicServiceDate(ConfigKey.QUERY_NOT_NULL_FLAG);
		} catch (Exception e) {
			QUARY_NOT_NULL_FLAG = "false";
			log.warn("实时指标-数据上报-远程调用-基础服务-获取公共参数配置-失败-{}参数采用默认值：'false'", ConfigKey.QUERY_NOT_NULL_FLAG);
		}
	}

	@Autowired
	private RemoteSystemService remoteSystemService;

	@Autowired
	private RemoteBusinessService remoteBusinessService;

	@Autowired
	private RemoteAlarmIndicatorsService remoteAlarmIndicatorsService;

	/**
	 * 查询告警类型比例
	 * @param params 业务告警请求对象
	 * @return 通用返回对象
	 */
	@Override
	public R<Object> queryAlarmTypeProportion(BusinessAlarmParams params) {

		// 获取表信息集
		MultipleTableInfo info = new MultipleTableInfo();
		info.setTableName(TableNameEnum.MYSQL_BUSI_BASE_ALARM_STAT.getName());
		List<MultipleTableInfo> tableInfos = Collections.singletonList(info);
		params.setMultipleTableInfoList(tableInfos);

		// 4、执行查询
		// 4.1、查询告警比例
		List<AlarmTypeProportionVo> rate = businessAlarmMapper.queryAlarmTypeProportion(params);
		// 4.2、查询告警详情列表
		List<AlarmTypeProportionVo> detail = businessAlarmMapper.queryAlarmTypeDetail(params);
		// 5、返回数据
		return R.ok(AlarmTypeRateVo.build(rate, detail));
	}

	/**
	 * 查询告警类型数top
	 * @param params 业务告警请求对象
	 * @return 通用返回对象
	 */
	@Override
	public R<Object> queryAlarmTypeCountTop(BusinessAlarmParams params) {

		// 获取表信息集
		MultipleTableInfo info = new MultipleTableInfo();
		info.setTableName(TableNameEnum.MYSQL_BUSI_BASE_ALARM_STAT.getName());
		List<MultipleTableInfo> tableInfos = Collections.singletonList(info);
		params.setMultipleTableInfoList(tableInfos);


		// 4、执行查询
		List<AlarmTypeCountTopVo> list = businessAlarmMapper.queryAlarmTypeCountTop(params);
		// 5、返回数据
		return R.ok(list);
	}


	/**
	 * 查询影响区域最多的告警topN
	 *
	 * @param params 业务告警请求对象
	 * @return 通用返回对象
	 */
	@Override
	public R<Object> queryInfluenceAreaTop (BusinessAlarmParams params) {

		// 获取表信息集
		MultipleTableInfo info = new MultipleTableInfo();
		info.setTableName(TableNameEnum.MYSQL_BUSI_BASE_ALARM_STAT.getName());
		List<MultipleTableInfo> tableInfos = Collections.singletonList(info);
		params.setMultipleTableInfoList(tableInfos);


		// 4、执行查询
		List<InfluenceAreaTopVo> list = businessAlarmMapper.queryInfluenceAreaTop(params);
		List<InfluenceAreaTopVo> nameList = businessAlarmMapper.queryInfluenceAreaTopList(params);
		// 5、转换业务数据
		Map<String, List<String>> nameMap = new HashMap<>();
		nameList.forEach(item -> {
			List<String> temp = nameMap.computeIfAbsent(item.getAlarmType(), k-> new ArrayList<>());
			temp.add(item.getAlarmTypeName());
		});
		// 设置top 区域名称列表
		list.forEach(item -> item.setAreaName(nameMap.computeIfAbsent(item.getAlarmType(), k-> new ArrayList<>())));
		// 6、返回数据
		return R.ok(list);
	}

	/**
	 * 查询影响业务最多的故障top
	 * @param params 业务告警请求对象
	 * @return 通用返回对象
	 */
	@Override
	public R<Object> queryInfluenceBusiTop(BusinessAlarmParams params) {

		// 获取表信息集
		MultipleTableInfo info = new MultipleTableInfo();
		info.setTableName(TableNameEnum.MYSQL_BUSI_BASE_ALARM_STAT.getName());
		List<MultipleTableInfo> tableInfos = Collections.singletonList(info);
		params.setMultipleTableInfoList(tableInfos);


		// 4、执行查询
		List<InfluenceBusiTopVo> list = businessAlarmMapper.queryInfluenceBusiTop(params);
		List<InfluenceBusiTopVo> nameList = businessAlarmMapper.queryInfluenceBusiTopList(params);
		// 5、转换业务数据
		Map<String, List<String>> nameMap = new HashMap<>();
		nameList.forEach(item -> {
			List<String> temp = nameMap.computeIfAbsent(item.getAlarmType(), k-> new ArrayList<>());
			temp.add(item.getAlarmTypeName());
		});
		// 设置top 区域名称列表
		list.forEach(item -> item.setBusiName(nameMap.computeIfAbsent(item.getAlarmType(), k-> new ArrayList<>())));
		// 6、返回数据
		return R.ok(list);
	}



	@Override
	public R<Object> queryInfluenceSysTop(BusinessAlarmParams params) {

		// 获取表信息集
		MultipleTableInfo info = new MultipleTableInfo();
		info.setTableName(TableNameEnum.MYSQL_BUSI_BASE_ALARM_STAT.getName());
		List<MultipleTableInfo> tableInfos = Collections.singletonList(info);
		params.setMultipleTableInfoList(tableInfos);


		// 4、执行查询
		List<InfluenceSysTopVo> list = businessAlarmMapper.queryAlarmSystemTopN(params);
		List<InfluenceSysTopVo> nameList = businessAlarmMapper.queryAlarmSystemTopNList(params);
		// 5、转换业务数据
		Map<String, List<String>> nameMap = new HashMap<>();
		nameList.forEach(item -> {
			List<String> temp = nameMap.computeIfAbsent(item.getAlarmType(), k-> new ArrayList<>());
			temp.add(item.getAlarmTypeName());
		});
		// 设置top 系统名称列表
		list.forEach(item -> item.setSystemName(nameMap.computeIfAbsent(item.getAlarmType(), k-> new ArrayList<>())));
		// 6、返回数据
		return R.ok(list);
	}

	/**
	 * 查询发生次数最多的故障top
	 * @param params 业务告警请求对象
	 * @return 通用返回对象
	 */
	@Override
	public R<Object> queryHappenCountAlarmTop(BusinessAlarmParams params) {

		// 获取表信息集
		MultipleTableInfo info = new MultipleTableInfo();
		info.setTableName(TableNameEnum.MYSQL_BUSI_BASE_ALARM_STAT.getName());
		List<MultipleTableInfo> tableInfos = Collections.singletonList(info);
		params.setMultipleTableInfoList(tableInfos);

		// 4、执行查询
		List<HappenCountAlarmTopVo> list = businessAlarmMapper.queryHappenCountAlarmTop(params);
		// 5、返回数据
		return R.ok(list);
	}

	/**
	 * 查询告警统计列表
	 * @param params 业务告警请求对象
	 * @return 通用返回对象
	 */
	@Override
	public R<Object> queryAlarmStatisticsList(BusinessAlarmParams params) {


		// 获取表信息集
		MultipleTableInfo info = new MultipleTableInfo();
		info.setTableName(TableNameEnum.MYSQL_BUSI_BASE_ALARM_STAT.getName());
		List<MultipleTableInfo> tableInfos = Collections.singletonList(info);
		params.setMultipleTableInfoList(tableInfos);


		if (StringUtils.isEmpty(params.getOrderByColumn())) {
			params.setIsAsc("desc");
			params.setOrderByColumn("recentTime");
		}
		// 4、设置分页对象，如果不传pageNum或pageSize，相当于不分页
		Page<BusinessStatisticsVo> page = null;
		if (params.getPageNum() > 0 && params.getPageSize() > 0) {
			page = new Page<>(params.getPageNum(), params.getPageSize());
		}
		// 5、执行查询
		List<AlarmStatisticsVo> list = businessAlarmMapper.queryAlarmStatisticsList(params, page);
		// 6、转换业务数据
		// 7、返回分页对象
		if (page == null) {
			return R.ok(new PageDataInfo(list.size(), list));
		}
		return R.ok(new PageDataInfo(page, list));
	}

	/**
	 * 查询告警详情列表
	 * @param params 业务告警请求对象
	 * @return 通用分页对象
	 */
	@Override
	public R<PageDataInfo> queryAlarmDetailList(BusinessAlarmParams params) {
		Page<AlarmDetailVo> page = new Page<>(params.getPageNum(), params.getPageSize());
		// 获取参数
		params.setQueryNotNullFlag(QUARY_NOT_NULL_FLAG);

		// 查询数据
		List<AlarmDetailVo> alarmDetailVos = businessAlarmMapper.queryAlarmDetailList(page, params);

		return R.ok(new PageDataInfo(page, alarmDetailVos));
	}


	/**
	 * 查询系统告警总览列表
	 *
	 * @param params 系统告警总览请求对象
	 * @return 通通用返回对象
	 */
	@Override
	public R<Object> querySystemAlarmOverviewList(AlarmOverviewParams params) {

		// 获取表信息集
		MultipleTableInfo info = new MultipleTableInfo();
		info.setTableName(TableNameEnum.MYSQL_BUSI_BASE_ALARM_STAT.getName());
		List<MultipleTableInfo> tableInfos = Collections.singletonList(info);
		params.setMultipleTableInfoList(tableInfos);

		// 1.4、设置分页对象
		Page<AlarmOverviewVo> page = new Page<>(params.getPageNum(), params.getPageSize());
		// 1.5、执行查询
		List<AlarmOverviewVo> list = businessAlarmMapper.querySystemAlarmOverviewList(params, page);


		// 获取表信息集
		info = new MultipleTableInfo();
		info.setTableName(TableNameEnum.KHGZ_BUSI_SYS_DETAIL_STAT.getName());
		tableInfos = Collections.singletonList(info);
		params.setMultipleTableInfoList(tableInfos);

		// 2.4、执行查询
		List<AlarmOverviewVo> otherFields = businessAlarmMapper.querySysDetailStatList(params);

		// 3、转换业务数据
		Map<String, AlarmOverviewVo> temp = new HashMap<>();
		if (null != otherFields) {
			otherFields.forEach(item -> {
				String key = item.getSystemId() + "#" + item.getBusinessCode();
				temp.put(key, item);
			});
		}
		list.forEach(item -> {
			String key = item.getSystemId() + "#" + item.getBusinessCode();
			AlarmOverviewVo vo = temp.get(key);
			if (null != vo) {
				item.setVisitCount(vo.getVisitCount()==null?0:vo.getVisitCount());
				item.setCompleteCount(vo.getCompleteCount()==null?0:vo.getCompleteCount());
				item.setSuccessRateTmp(vo.getSuccessRateTmp()==null?0.00:vo.getSuccessRateTmp());
				item.setHealthRateTmp(vo.getHealthRateTmp()==null?0.00:vo.getHealthRateTmp());
			}else{
				item.setVisitCount(0);
				item.setCompleteCount(0);
				item.setAlarmCount(0);
				item.setSuccessRateTmp(0.00);
				item.setHealthRateTmp(0.00);
			}

			item.handleNumberFormat();
		});
		// 手动排序
		if ("completeCount".equals(params.getOrderByColumn())) {
			if ("desc".equals(params.getIsAsc())) {
				list.sort((o1, o2) -> o2.getCompleteCount().compareTo(o1.getCompleteCount()));
			} else {
				list.sort(Comparator.comparing(AlarmOverviewVo::getCompleteCount));
			}
		} else if ("successRate".equals(params.getOrderByColumn())) {
			if ("desc".equals(params.getIsAsc())) {
				list.sort((o1, o2) -> o2.getSuccessRateTmp().compareTo(o1.getSuccessRateTmp()));
			} else {
				list.sort(Comparator.comparing(AlarmOverviewVo::getSuccessRateTmp));
			}
		} else if ("healthRate".equals(params.getOrderByColumn())) {
			if ("desc".equals(params.getIsAsc())) {
				list.sort((o1, o2) -> o2.getHealthRateTmp().compareTo(o1.getHealthRateTmp()));
			} else {
				list.sort(Comparator.comparing(AlarmOverviewVo::getHealthRateTmp));
			}
		} else if ("visitCount".equals(params.getOrderByColumn())) {
			if ("desc".equals(params.getIsAsc())) {
				list.sort((o1, o2) -> o2.getVisitCount().compareTo(o1.getVisitCount()));
			} else {
				list.sort(Comparator.comparing(AlarmOverviewVo::getVisitCount));
			}
		} else if ("alarmCount".equals(params.getOrderByColumn())) {
			if ("desc".equals(params.getIsAsc())) {
				list.sort((o1, o2) -> o2.getAlarmCount().compareTo(o1.getAlarmCount()));
			} else {
				list.sort(Comparator.comparing(AlarmOverviewVo::getAlarmCount));
			}
		}
		// 4、返回数据
		return R.ok(new PageDataInfo(page, list));
	}



	@Override
	public R<Object> queryHistogramDetail(HistoGramParams params)  {
		params.handleQueryTime();
		// 查询周期柱状图
		List<HistoGramVo> list = businessAlarmMapper.queryHistoGramVoList(params);

		// 补偿
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");

		Map<String, HistoGramVo> existMap = new HashMap<>();
		for (HistoGramVo histoGramVo : list) {
			try {
				// 将数据库中返回的cycle_time 格式转为 yyyyMMdd
				histoGramVo.setCycleTime(dateFormat.format(dateTimeFormat.parse(histoGramVo.getCycleTime())));
				existMap.put(histoGramVo.getCycleTime(), histoGramVo);
			} catch (java.text.ParseException e) {
				e.printStackTrace();
			}
		}
		params.getQueryTimeList().forEach(queryTime -> {
			if (!existMap.containsKey(queryTime)) {
				list.add(HistoGramVo.build(queryTime, 0));
			}

		});

		// 排序
		list.sort(Comparator.comparing(HistoGramVo::getCycleTime));


		return R.ok(list);
	}

	@Override
	public R<Object> queryUserAlarmList(UserIdentifyAlarmParams params) {
		Page<UserIdentifyAlarmVo> page = new Page<>(params.getPageNum(), params.getPageSize());

		params.setQueryNotNullFlag(QUARY_NOT_NULL_FLAG);

		// 查询数据
		List<UserIdentifyAlarmVo> userIdentifyAlarmVos = businessAlarmMapper.queryUserAlarmList(page, params);

		return R.ok(new PageDataInfo(page, userIdentifyAlarmVos));
	}


	/**
	 * 查询告警详情列表和分布
	 *
	 * @param params 告警参数
	 * @return 通用返回对象
	 */
	@Override
	public R<Object> queryAlarmDistribution(AlarmDistributionParams params) {
		List<AlarmDistributionVo> adVoList = new ArrayList<>();

		// 获取参数
		params.setQueryNotNullFlag(QUARY_NOT_NULL_FLAG);

		List<AlarmDistributionVo> allList = businessAlarmMapper.queryAlarmDistribution(params);

		// 设置vo对象
		allList.forEach(item -> {
			AlarmDistributionVo adVo = new AlarmDistributionVo();
			adVo.setTimeLabel(dropSec.format(dtf.parse(item.getTimeLabel())));
			adVo.setAlarmCount(1);
			adVoList.add(adVo);
		});

		// 归并数据
		Integer scale = null;
		if (params.getScale() != null) {
			scale = DynamicTableNameUtil.getScaleByMinScaleAndParam(60, params.getScale());
		}
		List<MergeField> mergeFieldList = new ArrayList<>();
		mergeFieldList.add(new MergeField("alarmCount"));
		Map<String, Object> map = MergeDataUtil.mergeData(new MergeDataConfig.Builder(
				AlarmDistributionVo.class,
				adVoList,
				params.getStartTime(),
				params.getEndTime(),
				mergeFieldList)
				.labelTimeFormatter("MM-dd'\n'HH:mm")
				.scale(scale)
				.cycleTimeKey("timeLabel")
				.build());

		return R.ok(map);
	}


	/**
	 * 查询告警详情
	 *
	 * @param params 请求参数
	 * @return 通用返回对象
	 */
	@Override
	public R<Object> queryReturnCodeDetail(AlarmDistributionParams params) {
		Page<ReturnCodeDetailVo> page = new Page<>(params.getPageNum(), params.getPageSize());
		params.setQueryNotNullFlag(QUARY_NOT_NULL_FLAG);

		// 查询数据
		List<ReturnCodeDetailVo> returnCodeDetailVos = businessAlarmMapper.queryReturnCodeDetailList(page, params);

		return R.ok(new PageDataInfo(page, returnCodeDetailVos));
	}


	@Override
	public R<Object> queryAlarmLevelList() {
		List<AlarmLevelVo> vo = businessAlarmMapper.queryAlarmLevelList();
		return R.ok(vo);
	}


	@Override
	public R<Object> alarmSysAndBusiList(AlarmSysAndBusiParams params) {


		// 获取表信息集
		MultipleTableInfo info = new MultipleTableInfo();
		info.setTableName(TableNameEnum.MYSQL_BUSI_BASE_ALARM_STAT.getName());
		List<MultipleTableInfo> tableInfos = Collections.singletonList(info);
		params.setMultipleTableInfoList(tableInfos);


		if ("".equals(params.getBusinessCode())) {
			params.setBusinessCode(null);
		}
		// 当businessCode 参数值为 -1时,表示businessCode 为空
		if (params.getBusinessCode() != null && "-1".equals(params.getBusinessCode())) {
			params.setBusinessCode("");
		}
		// 4、设置分页对象，如果不传pageNum或pageSize，相当于不分页
		Page<AlarmSysAndBusiVo> page = null;
		if (params.getPageNum() > 0 && params.getPageSize() > 0) {
			page = new Page<>(params.getPageNum(), params.getPageSize());
		}
		// 5、执行查询
		List<AlarmSysAndBusiVo> list = businessAlarmMapper.alarmSysAndBusiList(page, params);
		// 6、转换业务数据
		// 7、返回分页对象
		if (page == null) {
			return R.ok(new PageDataInfo(list.size(), list));
		}
		return R.ok(new PageDataInfo(page, list));
	}


	@Override
	public void alarmSysAndBusiListExport(AlarmSysAndBusiParams params, HttpServletResponse response) throws IOException {

		// 获取表信息集
		MultipleTableInfo info = new MultipleTableInfo();
		info.setTableName(TableNameEnum.MYSQL_BUSI_BASE_ALARM_STAT.getName());
		List<MultipleTableInfo> tableInfos = Collections.singletonList(info);
		params.setMultipleTableInfoList(tableInfos);



		// 4、执行查询
		List<AlarmSysAndBusiVo> list = businessAlarmMapper.alarmSysAndBusiListExport(params);
		// 5、导出
		for (int i = 0; i < list.size(); i++) {
			AlarmSysAndBusiVo vo=list.get(i);
			vo.setNum(i + 1);
		}
		String title = "单业务告警统计列表";
		String fileName = title + System.currentTimeMillis();
		// 设置excel文件标题
		List<String> titleParams = new ArrayList<>();
		titleParams.add(title);
		R<ConfSystem> systemRes = remoteSystemService.getSystemById(params.getSystemId());
		if (systemRes.getCode() != 0){
			log.error("远程调用配置系统获取系统名称错误:{}",systemRes.getMsg());
		}
		titleParams.add(systemRes.getData().getName());
		R<ConfBusiness> businessRes = remoteBusinessService.getBusinessByBusinessCode(params.getBusinessCode());
		if (businessRes.getCode() != 0){
			log.error("远程调用配置系统获取业务名称错误:{}",systemRes.getMsg());
		}
		titleParams.add(businessRes.getData() != null ? businessRes.getData().getBusinessCode() : "");
		if (params.getAlarmIndicatorId() != null) {
			R<ConfAlarmIndicators> confAlarmIndicatorsR = remoteAlarmIndicatorsService.queryById(params.getAlarmIndicatorId());
			if (confAlarmIndicatorsR.getCode() != 0){
				log.error("远程调用配置系统获取告警信息错误:{}",confAlarmIndicatorsR.getMsg());
			}
			titleParams.add(confAlarmIndicatorsR.getData() != null ? confAlarmIndicatorsR.getData().getName() : "" );
		}
		String formTitleName = ExcelTitleUtils.formTitleName(titleParams,params.getStartTime(),params.getEndTime());
		// 设置列名
		List<List<String>> headList = new ArrayList<>();
		List<String> titleList = Arrays.asList("序号", "系统名称", "业务名称", "告警类型", "告警实值", "次数");
		titleList.forEach(s -> {
			List<String> childHeadList = new ArrayList<>();
			childHeadList.add(formTitleName);
			childHeadList.add(s);
			headList.add(childHeadList);
		});
		ExcelUtil.writeExcel(AlarmSysAndBusiVo.class, fileName, title, list, headList, 20, response);
	}

	/**
	 * 告警实值统计列表
	 * @param params
	 * @return
	 */

	@Override
	public R<Object> alarmOverviewList(AlarmSysAndBusiParams params) {



		// 获取表信息集
		MultipleTableInfo info = new MultipleTableInfo();
		info.setTableName(TableNameEnum.MYSQL_BUSI_BASE_ALARM_STAT.getName());
		List<MultipleTableInfo> tableInfos = Collections.singletonList(info);
		params.setMultipleTableInfoList(tableInfos);


		// 4、设置分页对象，如果不传pageNum或pageSize，相当于不分页
		Page<AlarmOverviewListVo> page = null;
		if (params.getPageNum() > 0 && params.getPageSize() > 0) {
			page = new Page<>(params.getPageNum(), params.getPageSize());
		}
		// 5、执行查询
		List<AlarmOverviewListVo> list = businessAlarmMapper.alarmOverviewList(page, params);
		// 6、转换业务数据
		// 7、返回分页对象
		if (page == null) {
			return R.ok(new PageDataInfo(list.size(), list));
		}
		return R.ok(new PageDataInfo(page, list));
	}

	/**
	 * 告警总览列表导出
	 * @param params
	 * @return
	 */
	@Override
	public void alarmOverviewListExport(AlarmSysAndBusiParams params, HttpServletResponse response) throws ParseException, IOException, ParseException {

		// 获取表信息集
		MultipleTableInfo info = new MultipleTableInfo();
		info.setTableName(TableNameEnum.MYSQL_BUSI_BASE_ALARM_STAT.getName());
		List<MultipleTableInfo> tableInfos = Collections.singletonList(info);
		params.setMultipleTableInfoList(tableInfos);


		// 4、执行查询
		List<AlarmOverviewListVo> list = businessAlarmMapper.alarmOverviewListExport(params);
		// 5、导出
		for (int i = 0; i < list.size(); i++) {
			AlarmOverviewListVo vo=list.get(i);
			vo.setNum(i + 1);
		}
		String title = "告警总览列表";
		String fileName = title + System.currentTimeMillis();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		String formTitleName = title + simpleDateFormat.format(simpleDateFormat.parse(params.getStartTime())) + "~"
				+ simpleDateFormat.format(simpleDateFormat.parse(params.getEndTime()));
		List<List<String>> headList = new ArrayList<>();
		List<String> titleList = Arrays.asList("序号", "告警类型", "告警实值", "告警次数");
		titleList.forEach(s -> {
			List<String> childHeadList = new ArrayList<>();
			childHeadList.add(formTitleName);
			childHeadList.add(s);
			headList.add(childHeadList);
		});
		ExcelUtil.writeExcel(AlarmOverviewListVo.class, fileName, title, list, headList, 20, response);
	}
}
